package indi.zn.commons.easiness;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.collect.Lists;

public class Regulars {
	
	
	public static List<String> matcherStr(String patternstr,String input) {
		Pattern pattern = Pattern.compile(patternstr);  
   	  
   	  Matcher matcher = pattern.matcher(input);
   
   	  List<String> reslist=Lists.newArrayList();
   	  
   	  while(matcher.find())
   	  {
   		  
   		reslist.add(matcher.group());
   		 
   	  }
		return reslist;
	
	}

	
	public static String replaceMatchIndex(Matcher matcher,int findindex,String rsplaceStr) {
		
		 matcher.reset();
		String res=null;		
		 boolean result = matcher.find();
         
         if (result) {
      	   
      	   int i=1;
      	  
             StringBuffer sb = new StringBuffer();
             do {
          	   
          	   if(i==findindex) {
       
          	   matcher.appendReplacement(sb,rsplaceStr);
                 result = matcher.find();
          	   }else {  

          		   matcher.appendReplacement(sb,matcher.group());
          		   result = matcher.find();
          	   }
          	   i++;
          	   
             } while (result);
             matcher.appendTail(sb);
             res=  sb.toString();
         }
		return res;
	}
	

	
}
